//
//  GameDetailCorrelationSubView.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2022/9/30.
//

#import "GameDetailCorrelationSubView.h"

@interface GameDetailCorrelationSubView ()

@property (weak, nonatomic) IBOutlet YYAnimatedImageView *gameIcon;
@property (weak, nonatomic) IBOutlet UILabel *gameNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *daijinquan;
@property (weak, nonatomic) IBOutlet UILabel *gameSubNameLabel;

@property (weak, nonatomic) IBOutlet UIView *signView;
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;

@end

@implementation GameDetailCorrelationSubView

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    [self.daijinquan cornerRectType:(UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomRight) withCornerRadius:7.5];
}

- (void)setDetailModel:(GameDetailNewModel *)detailModel
{
    _detailModel = [GameDetailNewModel mj_objectWithKeyValues:[LocalData getMenudicWithKey:@"gamedetail"]];
    
    [self.gameIcon yy_setImageWithURL:[NSURL URLWithString:_detailModel.gameMainIcon] placeholder:placeholder_image];
    self.gameNameLabel.text = _detailModel.gameName;
    self.gameSubNameLabel.text = [NSString stringWithFormat:@" %@ ", _detailModel.gameSubName];
    self.daijinquan.hidden = !_detailModel.isDaijinquan.boolValue;
    
    [self.signView removeAllSubviews];
    UIView *temsignOneView = nil;
    NSInteger count = _detailModel.gameSignArr.count;
    if (count > 3) count = 3;
    for (NSInteger i = 0; i < count; i++) {
        NSString *signStr = _detailModel.gameSignArr[i];
        UIView *signOneView = [[UIView alloc] init];
        signOneView.backgroundColor = UIColorHex(0xEBEBEB);
        signOneView.layer.cornerRadius = 4;
        signOneView.layer.masksToBounds = YES;
        [self.signView addSubview:signOneView];
        UILabel *signLabel = [[UILabel alloc] init];
        signLabel.text = signStr;
        signLabel.font = [UIFont systemFontOfSize:12];
        signLabel.textColor = kColor888888;
        [signOneView addSubview:signLabel];
        [signOneView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.signView).offset(5);
            if (temsignOneView) {
                make.left.equalTo(temsignOneView.mas_right).offset(5);
            } else {
                make.left.equalTo(self.signView);
            }
        }];
        [signLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(signOneView);
            make.top.equalTo(signOneView).offset(2);
            make.left.equalTo(signOneView).offset(3);
        }];
        temsignOneView = signOneView;
    }
    
    self.scoreLabel.text = [NSString stringWithFormat:@"%@分", _detailModel.gameScore];
    
    self.typeLabel.text = [_detailModel.gameTypes componentsJoinedByString:@"|"];
}

@end
